<style lang="scss">
    .my-input-format {
        .el-input__inner {
            width: 100%;
            text-align: right !important;
        }
    }
</style>

<template>
    <el-input class="my-input-format" v-model="inputValue" size="small" @change="doChange">
    </el-input>
</template>

<script>
    export default {
        name: 'my-input-format',
        model: {
            prop: 'value',
            event: 'change'
        },
        props: {
            disabled: false,
            value: {
                type: Number,
                default: 0
            }
        },
        data () {
            return {
                inputValue: this.$formatMoney(this.value, 2)
            }
        },
        methods: {
            doChange (value) {
                let reg = new RegExp(',', 'g')
                this.inputValue = this.$formatMoney(value.replace(reg, ''), 2)
                this.$emit('change', Number(value.replace(reg, '')))
            }
        },
        watch: {
            value (newValue) {
                this.$nextTick(() => {
                    this.inputValue = this.$formatMoney(newValue, 2)
                })
            }
        },
        components: {},
        computed: {},
        mounted: function () {
        }
    }
</script>
